<template>
  <el-select
    :value="value"
    :placeholder="placeholder"
    :clearable="clearable"
    :multiple="multiple"
    :popper-class="listClass"
    filterable
    @change="onChange"
  >
    <el-option
      v-for="item of options"
      :key="item.value"
      :label="item.label"
      :value="item.value"
    />
  </el-select>
</template>

<script>
import { Select } from 'element-ui'

export default {
  name: 'AdminSelect',
  props: {
    ...Select.props,
    options: {
      type: Array,
      required: true,
    },
    listStyle: {
      validator(value) {
        return ['v', 'h'].indexOf(value) !== -1
      },
    },
  },
  computed: {
    listClass() {
      return this.listStyle === 'h' ? 'horizontal' : ''
    },
  },
  methods: {
    onChange(value) {
      this.$emit('input', value)
    },
  },
}
</script>

<style rel="stylesheet/scss" lang="scss">
.el-select-dropdown.horizontal {
  .el-select-dropdown__item {
    display: inline-block;
    margin-left: 5px;
    border-radius: 4px;
    padding: 0 10px;

    &.selected {
      background-color: #f5f7fa !important;

      &::after {
        content: '' !important;
      }
    }
  }
}
</style>
